// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        logoAnima: [cc.Node],
    },
    onLoad() {

    },
    //播放加载动画
    play(){
        let fadeIn = cc.fadeIn(0.2);
        let fadeOut = cc.fadeOut(0.2);
        let seq = cc.sequence(fadeOut, fadeIn);
        let callBack = cc.callFunc(this.callBack0, this);
        let sequence = cc.sequence(seq, seq, seq, callBack);
        this.logoAnima[0].runAction(sequence);
        this.blink(this.logoAnima[0], 0.2);
    },
    //重置动画
    reset(){
        // console.log('重置');
        this.node.stopAllActions();
        this.logoAnima[0].stopAllActions();
        this.logoAnima[1].stopAllActions();
        this.logoAnima[2].stopAllActions();
        this.logoAnima[3].stopAllActions();
        let js = this.logoAnima[2].getComponent('logoVirusAnim');
        js.reset();
        js = this.logoAnima[3].getComponent('logoVirusAnim');
        js.reset();

    },
    //上移动画
    moveOut(){
        this.reset();
        this.node.runAction(cc.moveTo(0.5,cc.v2(-20,960)).easing(cc.easeBackIn()));

    },
    moveIn(){
        this.reset();
        this.node.runAction(cc.moveTo(0.5,cc.v2(-20,445)).easing(cc.easeBackOut()));
    },
    blink(node, time) {
        let fadeIn = cc.fadeIn(time);
        let delay = cc.delayTime(0.2);
        let fadeOut = cc.fadeOut(time);
        let seq = cc.sequence(fadeOut, delay, fadeIn);
        node.runAction(seq).repeatForever();
    },
    //进度条变长，且闪烁
    callBack0() {
        // cc.log('动画1结束');
        // console.log('动画1结束');
        let scale = cc.scaleTo(0.5, 0.9, 1);
        let callBack2 = cc.callFunc(this.callBack1, this);
        let seq = cc.sequence(scale, callBack2);
        this.logoAnima[1].runAction(seq);
        this.blink(this.logoAnima[1], 0.2);
    },
    //病毒移动且缩放
    callBack1() {
        console.log('move and scale');
        let virus1Action = cc.spawn(cc.moveTo(0.5, cc.v2(348, 99)), cc.scaleTo(0.5, 1, 1));
        let virus2Action = cc.spawn(cc.moveTo(0.5, cc.v2(388, -84)), cc.scaleTo(0.5, 1, 1));
        let callFunc = cc.callFunc(this.callBack2, this);
        let action1 = cc.sequence(virus1Action, callFunc);
        let action2 = cc.sequence(virus2Action, callFunc);
        this.logoAnima[2].runAction(action1);
        this.logoAnima[3].runAction(action2);
        // this.callBack2();
    },
    callBack2() {
        let dispearAction = this.logoAnima[2].getComponent('logoVirusAnim');
        dispearAction.init(348, 99, 120);
        dispearAction.begin();

        dispearAction = this.logoAnima[3].getComponent('logoVirusAnim');
        dispearAction.init(388, -84, 80);
        dispearAction.begin();
        // console.log(begin1);

    },
    start() {

    },

    // update (dt) {},
});